package cn.manyufun.myf.common.webview;

import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;

/**
 * Created by Xiao on 2018-02-12.
 */

public class Scheme {
    private Activity activity;
    private boolean isMYF = false;
    private HashMap<String, String> hashMap;
    private String Host;
    private boolean over = false;

    private boolean isHttp;

    public Scheme(URI uri) {

    }

    public Scheme(URI uri, Activity activity) {
        this.activity = activity;
        init(uri);
    }

    public Scheme(String url, Activity activity) {
        this.activity = activity;
        url = url.replaceAll(" ", "%20");
        try {
            URI uri = new URI(url);
            init(uri);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

    private void init(URI uri) {
        String scheme = uri.getScheme();
        String host = uri.getHost();
        String query = uri.getRawQuery();
        String path = uri.getPath();
        Log.i("xwx_schema", scheme + "|" + host + "|" + path + "|" + query);

        if (scheme.startsWith("http"))
            isHttp = true;
        if (scheme.equals("zzjj")) {
            Host = host;
            isMYF = true;
            Log.i("xwx_schema", scheme + "|" + host + "|" + path + "|" + query);
            if (!TextUtils.isEmpty(path)) {
                String pathstr = "";
                if (!TextUtils.isEmpty(query))
                    pathstr = "?" + query;
//                    CommonUtils.openActivity(host, path.substring(1) + pathstr, activity);
            }
            over = true;
        }
    }

    public boolean isMYF() {
        return isMYF;
    }

    public boolean isOver() {
        return this.over;
    }

    public HashMap<String, String> getHashMap() {
        return this.hashMap;
    }

    public String getHost() {
        return Host;
    }

    public boolean isHttp() {
        return isHttp;
    }
}
